package com.dfy.controller;

import com.dfy.common.Result;
import com.dfy.dto.ReviewDTO;
import com.dfy.service.ReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

@Slf4j
@RestController
@RequestMapping("/api/spots/{spotId}/reviews")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;

    @GetMapping
    public Result<Map<String, Object>> getSpotReviews(
            @PathVariable Long spotId,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        log.info("获取景点评论，spotId：{}，page：{}，size：{}", spotId, page, size);
        
        List<ReviewDTO> reviews = reviewService.getSpotReviews(spotId, page, size);
        int total = reviewService.getSpotReviewCount(spotId);
        
        Map<String, Object> response = new HashMap<>();
        response.put("reviews", reviews);
        response.put("total", total);
        response.put("page", page);
        response.put("size", size);
        
        return Result.success(response);
    }
} 